/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export interface ProjectConfig {
    projectName: string;
    projectPath: string;
    logPath: string;
    ohosSdkPath: string;
    hmsSdkPath: string;
    checkPath: string;
    apiVersion: number;
    fix: string;
    fixSelected: boolean;
    npmPath: string;
    npmInstallDir: string;
    reportDir: string;
    sdksThirdParty: string[];
    arkCheckPath: string;
    product: string;
    homecheck_log_level: string;
    arkanalyzer_log_level: string;
}

export function parseProjectConfig(config: any) {
    return {
        projectName: config.projectName ?? '',
        projectPath: config.projectPath ?? process.cwd(),
        logPath: config.logPath ?? './HomeCheck.log',
        ohosSdkPath: config.ohosSdkPath ?? '',
        hmsSdkPath: config.hmsSdkPath ?? '',
        checkPath: config.checkPath ?? '',
        apiVersion: config.sdkVersion ?? 14,
        fix: config.fix ?? 'false',
        fixSelected: config.fixSelected ?? false,
        npmPath: config.npmPath ? config.npmPath : 'npm',
        npmInstallDir: config.npmInstallDir ? config.npmInstallDir : './',
        reportDir: config.reportDir ? config.reportDir : './',
        sdksThirdParty: config.sdksThirdParty ?? [],
        arkCheckPath: config.arkCheckPath ?? '',
        product: config.product ?? '',
        homecheck_log_level: config.homecheck_log_level ?? 'info',
        arkanalyzer_log_level: config.arkanalyzer_log_level ?? 'error',
    }
}

export interface SelectedFileInfo {
    filePath: string;
    fixKey?: string[];
}

export const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
    projectName: "",
    projectPath: undefined!,
    logPath: "./HomeCheck.log",
    ohosSdkPath: "",
    hmsSdkPath: "",
    checkPath: "",
    apiVersion: 14,
    fix: "false",
    npmPath: "",
    npmInstallDir: "./",
    reportDir: "./report",
    arkCheckPath: "./",
    product: "default",
    sdksThirdParty: [],
    fixSelected: false,
    homecheck_log_level: "info",
    arkanalyzer_log_level: "error"
}
